<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/6/27 0027
  Time: 15:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript">
        function loadSencondCategory(){
            var categoryId = $("#topCategoryId").val();
            $("#secondCategoryId").html('<option value="">--请选择二级分类--</option>');
            $.ajax({
                type:"GET",
                url:"${ctx}/get_child_category/"+categoryId,
                dataType:"JSON",
                success: function(obj){
                    for(var i=0;i<obj.length;i++){
                        $("#secondCategoryId").append("<option value='"+obj[i].categoryId+"'>"+obj[i].categoryName+"</option>");
                    }
                }
            });
        }
    </script>
</head>

<body>
<div class="row">
    <div class="col-md-12">
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title">
            分类管理 <small>添加分类</small>
        </h3>
        <ul class="page-breadcrumb breadcrumb">
            <li>
                <i class="fa fa-home"></i>
                <a href="${ctx}/main">
                    首页
                </a>
                <i class="fa fa-angle-right"></i>
            </li>
            <li>
                <a href="${ctx}/pcategory/category_list">
                    分类商品管理
                </a>
                <i class="fa fa-angle-right"></i>
            </li>
            <li>
                <a href="#">
                    添加分类
                </a>
            </li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB-->
    </div>
</div>
<!-- END PAGE HEADER-->
<!------内容区----->
<div class="main">
<form:form modelAttribute="PCategoryModel" method="post" class="form-horizontal">
    <%--<form:hidden path="id"></form:hidden>--%>
    <div class="row">
        <div class="col-md-12">
            <form action="#" class="form-horizontal">
                <div class="form-group">
                    <label class="control-label col-md-3">分类名称：</label>
                    <div class="col-md-4">
    <form:input path="categoryName" cssClass="form-control" placeholder=""></form:input>
                        <span class="help-inline"></span>
                    </div>
    <form:errors path="categoryName" cssClass="field-validation-error" element="div"></form:errors>
                </div>

                <div class="form-group">
                    <label class="control-label col-md-3">上级分类：</label>
                    <div class="col-md-2">
                        <select  id="topCategoryId" onchange="loadSencondCategory()" name="topCategoryId" class="form-control" tabindex="1">
                                 <option  value="">--请选择一级分类--</option>
                            <c:forEach var="item" items="${topCategoryList}" >
                                  <option value="${item.categoryId}">${item.categoryName}</option>
                            </c:forEach>
                        </select>
                        <span class="help-inline"></span>
                    </div>
                    <div class="col-md-2" id="user-name-label">
                        <select id="secondCategoryId"class="form-control" name="secondCategoryId" tabindex="1">
                            <option   value="">--请选择二级分类--</option>
                                <%--<option  name="parentCategoryId" value="2">二级分类</option>--%>
                                <%--<option  name="parentCategoryId" value="3">三级分类</option>--%>
                        </select>
                        <span class="help-inline"></span>
                    </div>
                    <div class="col-md-4"><p class="form-control-static">（顶级分类无父分类）</p></div>
                </div>
                <div class="form-group">
                    <label class="control-label col-md-3">排序(倒序)：</label>
                    <div class="col-md-4">
                        <form:input path="orderNum" cssClass="form-control" placeholder="" type="number"></form:input>
                        <span class="help-inline"></span>
                    </div>
                     <form:errors path="orderNum" cssClass="field-validation-error" element="div"></form:errors>
                </div>
                <div class="form-group">
                    <div class="col-md-9 col-md-offset-3">
                        <button type="submit" class="btn blue">确定</button>
                        <button type="button" class="btn">取消</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</form:form>
</div>
</body>
</html>
